package com.gs.djys.guide;


import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;

import com.gs.djys.Base.MyAppliCation;
import com.gs.djys.R;
import com.gs.djys.Util.ToastUtils;
import com.gs.djys.Util.Utils;
import com.gs.djys.land.LandActivity;
import com.gs.djys.main.MainActivity;
import com.gs.djys.main.MainBean;
import com.gs.djys.mvp.MVPBaseActivity;

/**
 * @author 张成昆
 * @Description: (引导页)
 * @date 2019-7-23
 */

public class GuideActivity extends MVPBaseActivity<GuideContract.View, GuidePresenter> implements GuideContract.View {
    private Handler handler;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initdate();
    }

    @Override
    protected int getLayout() {
        return R.layout.act_guide;
    }

    private void initdate() {
        handler = new Handler();
        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
            finish();
        } else {
            if (Utils.isNull(MyAppliCation.spUtils.getString("UserName"))) {
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        startActivity(new Intent(GuideActivity.this, LandActivity.class));
                        finish();
                    }
                }, 500);
            } else {
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mPresenter.getTJ();
                    }
                }, 500);
            }
        }
    }

    @Override
    public void onRequestError(String msg) {
        ToastUtils.showShortToast(msg);
    }

    @Override
    public void getTJs(String mainBean) {
        MyAppliCation.spUtils.put("data",mainBean);
        Intent intent = new Intent(GuideActivity.this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}
